import com.KKd.pojo.*;
import com.KKd.service.*;
import com.KKd.utils.UUIDUtils;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author 14587
 * @date 2020/11/10 17:33
 */
@Resource
public class Mytest {
    @Test
    public void testUser(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserServiceImpl userMapper = (UserServiceImpl) context.getBean("userServiceImpl");
        Map<String, Object> map = userMapper.showUser();
        String username = (String) map.get("username");
        System.out.println(username);
    }
    @Test
    public void testBlog(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        BlogServiceImpl blogMapper = (BlogServiceImpl) context.getBean("blogServiceImpl");
        String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        blogMapper.addBlog(new Blog(1,"java从入门到放弃1",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃2",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃3",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃4",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃5",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃6",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃7",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃8",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃1",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃2",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃3",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃4",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃5",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃6",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃7",date,30,30,"daadsfweofa"));
        blogMapper.addBlog(new Blog(1,"java从入门到放弃8",date,30,30,"daadsfweofa"));
       /* blogMapper.addBlobThumbNum(2);
        blogMapper.addBlobThumbNum(2);
        blogMapper.addBlobThumbNum(2);
        System.out.println(blogMapper.queryThumbs(2));
        System.out.println(blogMapper.queryBlogs());
        blogMapper.updateBlog(new Blog(2,"java从入门到入土",new SimpleDateFormat("yyyy-MM dd").format(new Date()),100,30,null));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("title","java从入门到入土");
        System.out.println(blogMapper.queryBlog(map));
        blogMapper.deleteBlogById(4);
        blogMapper.queryBlogLike("jav");*/
        /*String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        blogMapper.addBlog(new Blog(1,"java从入门到放弃",date,30,30,"adfadfwww啊手动阀打发为佛教爱上你的富豪哇反垄断奥i俄法德轮番的法律卡的发文案的房间里可谓哦分安德列夫闻风偶爱的设计费滥发灯笼裤飞机啊丹佛i为"));
        List<Map<String, String>> maps = blogMapper.queryBlogTitleContent();
        for (Map<String, String> map : maps) {
            System.out.println(map.get("title"));
            System.out.println(map.get("comment"));
        }*/
       /* for (Blog blog : blogMapper.queryBlogExceptText()) {
            System.out.println(blog);
        }*/
    }
    @Test
    public void testComment(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        CommentServiceImpl commentMapper = (CommentServiceImpl) context.getBean("commentServiceImpl");
        String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        //commentMapper.addComment(new Comment(1, UUIDUtils.getUUID(),2,date,"你真棒",0,false));
        //commentMapper.addComment(new Comment(2, UUIDUtils.getUUID(),2,date,"针不戳",0,false));
        commentMapper.addComment(new Comment(0,UUIDUtils.getUUID(), UUIDUtils.getUUID(),42,date,"针不戳",0,false));

        commentMapper.addCommThumbNum(1);
        commentMapper.addCommThumbNum(1);
        commentMapper.addCommThumbNum(1);
        commentMapper.decCommThumbNum(1);
        System.out.println(commentMapper.queryComments(2));
        commentMapper.setCommentFirstById(2);
    }
    @Test
    public void testDiary(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        DiaryServiceImpl diaryMapper = (DiaryServiceImpl) context.getBean("diaryServiceImpl");
        String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        diaryMapper.addSelfDiary(new Diary(1,date,"只有胜过自己，才能胜过他人"));
        diaryMapper.addSelfDiary(new Diary(1,date,"只有胜过自己，才能胜过他人"));
        diaryMapper.addSelfDiary(new Diary(1,date,"只有胜过自己，才能胜过他人"));
        diaryMapper.addSelfDiary(new Diary(1,date,"只有胜过自己，才能胜过他人"));
        diaryMapper.addSelfDiary(new Diary(1,date,"只有胜过自己，才能胜过他人"));
        diaryMapper.addSelfDiary(new Diary(1,date,"只有胜过自己，才能胜过他人"));
        diaryMapper.addSelfDiary(new Diary(1,date,"只有胜过自己，才能胜过他人"));
        diaryMapper.addSelfDiary(new Diary(1,date,"只有胜过自己，才能胜过他人"));
        diaryMapper.addSelfDiary(new Diary(1,date,"只有胜过自己，才能胜过他人"));
        diaryMapper.addSelfDiary(new Diary(1,date,"只有胜过自己，才能胜过他人"));
        for (Diary queryDiary : diaryMapper.queryDiaries()) {
            System.out.println(queryDiary);
        }
        /*diaryMapper.updateDiary(new Diary(1,date,"不服输"));
        for (Diary queryDiary : diaryMapper.queryDiaries()) {
            System.out.println(queryDiary);
        }
        diaryMapper.deleteDiaryById(2);*/
    }
    @Test
    public void testChain(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        ChainServiceImpl chainMapper = (ChainServiceImpl) context.getBean("chainServiceImpl");
        chainMapper.addChain(new Chain(1,"http://www.baidu.com",false,"链接","2020-11-11"));
        chainMapper.addChain(new Chain(1,"http://www.baidu.com",false,"链接","2020-11-11"));
        chainMapper.addChain(new Chain(1,"http://www.baidu.com",false,"链接","2020-11-11"));
        chainMapper.addChain(new Chain(1,"http://www.baidu.com",false,"链接","2020-11-11"));
        chainMapper.addChain(new Chain(1,"http://www.baidu.com",false,"链接","2020-11-11"));
        chainMapper.addChain(new Chain(1,"http://www.baidu.com",false,"链接","2020-11-11"));
        chainMapper.addChain(new Chain(1,"http://www.baidu.com",false,"链接","2020-11-11"));
        chainMapper.addChain(new Chain(1,"http://www.baidu.com",false,"链接","2020-11-11"));
        for (Chain queryChain : chainMapper.queryChains()) {
            System.out.println(queryChain);
        }
        chainMapper.setChainFirstById(1);
        for (Chain queryChain : chainMapper.queryChains()) {
            System.out.println(queryChain);
        }
        chainMapper.deleteChainById(1);
    }
    @Test
    public void testCatalogue(){
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        CatalogueServiceImpl catalogueMapper = (CatalogueServiceImpl) context.getBean("catalogueServiceImpl");
        catalogueMapper.insertCatalogue(new Catalogue(null,1,null,"java"));
        catalogueMapper.insertCatalogue(new Catalogue(null,2,null,"mysql"));
        for (Catalogue catalogue : catalogueMapper.showCatalogue()) {
            System.out.println(catalogue);
        }
        for (Catalogue catalogue : catalogueMapper.showCatalogue()) {
            System.out.println(catalogue);
        }
        for (String s : catalogueMapper.showBlogTitleByCata(2)) {
            System.out.println(s);
        }
        catalogueMapper.deleteCatalogueById(3);
    }
}
